/*
2021-8-8
https://leetcode-cn.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/
*/
class Solution {
public:
    int minSwaps(string s) {
        int res=0;
        int minv=0;
        for(auto t:s)
        {
            int cnt=0;
            if(t=='[') cnt=1;
            else cnt=-1;
            res+=cnt;
            minv=min(minv,res);
        }
        
        return (-1*minv+1)/2;

    }
};
